import sensor, image, display, time, pyb
from pyb import Pin, Timer

sensor.reset() # 初始化sensor
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
#设置图像色彩格式，有RGB565色彩图和GRAYSCALE灰度图两种

sensor.set_framesize(sensor.QVGA) # 320*240大小的液晶屏

# 初始化lcd屏幕，lcdtype = 0为2.0寸屏幕，lcdtype = 1为2.8寸屏幕
lcd = display.SPIDisplay(width = 320, height = 240, refresh = 120, lcdtype = 1)

clock = time.clock()

tim = Timer(2, freq=1000)
ch = tim.channel(1, Timer.PWM, pin=Pin("P6"))
ch.pulse_width_percent(100)

while(True):
    clock.tick()
    adc  = pyb.ADCAll(12)
    img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)
    img.draw_string(10, 2, "FPS:%0.1f" % clock.fps(),\
                    color = (255, 0, 0), mono_space = False, scale = 2)
    lcd.write(img) # 拍照并显示图像，参数x_scale = 2可对图像就地进行缩放
    print(clock.fps())


